import nattyFetch from 'natty-fetch';
import {
  Toast
} from 'saltui';

import {
  urlPrefix,
  isDev,
  URLS
} from './variables';
import Loading from '../components/loading';

// See https://github.com/Jias/natty-fetch for more details.
const context = nattyFetch.context({
  mockUrlPrefix: urlPrefix,
  urlPrefix,
  mock: isDev,
  // jsonp: true,
  withCredentials: false,
  traditional: true,
  data: {
    _tb_token_: '',
  },
  timeout: 60000,
  didFetch: () => Toast.hide(),
  // 请按照需要开启
  fit(response) {
    return {
      success: response.success,
      content: response.content,
      error: {
        errorMsg: response.errorMsg,
        errorCode: response.errorCode,
        errorLevel: response.errorLevel,
      },
    };
  },
});

context.create('SomeModuleAPI', {
  getSomeInfo: {
    mockUrl: 'query/getSomeInfo.json',
    url: 'query/getSomeInfo.json',
    willFetch() {
      Toast.show({
        type: 'loading',
        content: 'Loading',
      });
    },
  },
});

context.create('ForumModuleAPI', {
  topPost: {
    mockUrl: 'query/operationSuccess.json',
    url: URLS.topPost,
    method: 'POST',
    postDataFomat: 'FORM',
    willFetch() {
      Toast.show({
        content: <Loading/>
      });
    }
  },
  essencePost: {
    mockUrl: 'query/operationSuccess.json',
    url: URLS.essencePost,
    method: 'POST',
    postDataFomat: 'FORM',
    willFetch() {
      Toast.show({
        content: <Loading/>
      });
    }
  },
  deletePost: {
    mockUrl: 'query/operationSuccess.json',
    url: URLS.deletePost,
    method: 'POST',
    postDataFomat: 'FORM',
    willFetch() {
      Toast.show({
        content: <Loading/>
      });
    }
  },
  postBoards: {
    mockUrl: 'query/postBoards.json',
    url: URLS.postBoards,
    willFetch() {
      Toast.show({
        content: <Loading/>
      });
    },
  },
  ifPost:{
    mockUrl: 'query/operationSuccess.json',
    url: URLS.ifPost,
    postDataFomat: 'FORM',
    willFetch() {
      Toast.show({
        content: <Loading/>
      });
    }
  },
  ifPetname:{
    mockUrl: 'query/operationSuccess.json',
    url: URLS.ifPetname,
    postDataFomat: 'FORM',
    willFetch() {
      Toast.show({
        content: <Loading/>
      });
    }
  },
  editPost: {
    mockUrl: 'query/operationSuccess.json',
    url: URLS.editPost,
    method: 'POST',
    postDataFomat: 'FORM',
    willFetch() {
      Toast.show({
        content: <Loading/>
      });
    }
  },
  replyPost: {
    mockUrl: 'query/operationSuccess.json',
    url: URLS.replyPost,
    method: 'POST',
    postDataFomat: 'FORM',
    willFetch() {
      Toast.show({
        content: <Loading/>
      });
    }
  },
  viewPost: {
    mockUrl: 'query/viewPost.json',
    url: URLS.viewPost,
    willFetch() {
      /*Toast.show({
        content: <Loading/>
      });*/
    },
  },
  getBoardTree: {
    mockUrl: 'query/getBoardTree.json',
    url: URLS.getBoardTree,
    willFetch() {
      Toast.show({
        content: <Loading/>
      });
    },
  },
  checkPost: {
    mockUrl: 'query/operationSuccess.json',
    url: URLS.checkPost,
    method: 'POST',
    postDataFomat: 'FORM',
    willFetch() {
      Toast.show({
        content: <Loading/>
      });
    },
  },
  infoPost: {
    mockUrl: 'query/info.json',
    url: URLS.infoPost,
    willFetch() {
      Toast.show({
        content: <Loading/>
      });
    },
  },
  queryUncheckCount: {
    mockUrl: 'query/queryUncheckCount.json',
    url: URLS.queryUncheckCount,
    willFetch() {
      
    },
  },
  initUserInfo: {
    mockUrl: 'query/initUserInfo.json',
    url: URLS.initUserInfo,
    willFetch() {

    },
  },
  getIfReadAll: {
    mockUrl: 'query/getIfReadAll.json',
    url: URLS.getIfReadAll,
    willFetch() {
      
    },
  },
  queryReplyCount: {
    mockUrl: 'query/queryReplyCount.json',
    url: URLS.queryReplyCount,
    willFetch() {
      
    },
  },
  postAllBoard: {
    mockUrl: 'query/postAllBoard.json',
    url: URLS.postAllBoard,
    willFetch() {
      Toast.show({
        content: <Loading/>
      });
    },
  },
  editPostBoard :{
    mockUrl: 'query/operationSuccess.json',
    url: URLS.editPostBoard,
    willFetch() {
      Toast.show({
        content: <Loading/>
      });
    }
  },
  postAllLabel: {
    mockUrl: 'query/postAllLabel.json',
    url: URLS.postAllLabel,
    willFetch() {
      Toast.show({
        content: <Loading/>
      });
    },
  },

   editPostLabel: {
    mockUrl: 'query/editPostLabel.json',
    url: URLS.editPostLabel,
    method: 'POST',
    postDataFomat: 'FORM',
    willFetch() {
      Toast.show({
        content: <Loading/>
      });
    }
  },
  getBoardInfo: {
    mockUrl: 'query/getBoardInfo.json',
    url: URLS.getBoardInfo,
    willFetch() {
      Toast.show({
        content: <Loading/>
      });
    },
  },
  viewReplyPost: {
    mockUrl: 'query/viewReplyPost.json',
    url: URLS.viewReplyPost,
    willFetch() {
      Toast.show({
        content: <Loading/>
      });
    },
  },
  returnInfo:{
    mockUrl: 'query/returnInfo.json',
    url: URLS.returnInfo,
    willFetch() {
      Toast.show({
        content: <Loading/>
      });
    },
  },
  returnPost:{
    mockUrl: 'query/returnPost.json',
    url: URLS.returnPost,
    willFetch() {
      Toast.show({
        content: <Loading/>
      });
    },
  },
  collectionPost: {
    mockUrl: 'query/collectionPost.json',
    url: URLS.collectionPost,
    method: 'POST',
    postDataFomat: 'FORM',
    willFetch() {
    },
  },
  queryPostPageComment:{
    mockUrl: 'query/queryPostPageComment.json',
    url: URLS.queryPostPageComment,
    willFetch() {
    },
  },
  getIntegralViewInfo: {
    mockUrl: 'query/getIntegralViewInfo.json',
    url: URLS.getIntegralViewInfo,
    willFetch() {

    },
  },
});

export default context.api;